//
//  GETableViewCell.m
//  ERP
//
//  Created by goldeney on 15/3/12.
//  Copyright (c) 2015年 ShangHai Goldeneye Techonology Co.,Ltd. All rights reserved.
//

#import "GEInputTableViewCell.h"
#import "GEPickerTextField.h"
#import "GEDateTextField.h"
#import "GEMultiPickerTextField.h"
#import "IQUIView+IQKeyboardToolbar.h"
#import "NSString+handle.h"

@interface GEInputTableViewCell ()<UITextFieldDelegate>

@property (nonatomic,strong) ServiceParametModel *wbModel;
@property (nonatomic,strong) WebServiceCommonRequest *erpModel;

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *markLabel;
@property (nonatomic,strong) UITextField *field;
@property (nonatomic,strong) UIView *view;
@property (nonatomic,strong) UIActivityIndicatorView *activity;
@property (nonatomic,strong) UIButton *editSelectButton;

@property (nonatomic,strong) GEPickerTextField *pickerTextField;
@property (nonatomic,strong) GEMultiPickerTextField *multiPicker;
@property (nonatomic,strong) GEDateTextField *dateTextField;

@property (nonatomic,strong) NSMutableArray *textFieldMulti;

@property (nonatomic,strong) NSString *filter;
@property (nonatomic,assign) NSInteger filedLimitLength;

@end

@implementation GEInputTableViewCell

@synthesize titleLabel;
@synthesize markLabel;
@synthesize field;
@synthesize view;
@synthesize activity;
@synthesize pickerTextField;
@synthesize multiPicker;
@synthesize dateTextField;
@synthesize editSelectButton;

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier model:(ServiceParametModel*)model
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.wbModel = model;
        [self drawRowInputTableCell];
    }
    return self;
}

- (id)initWithInputSelectReuseIdentifier:(NSString *)reuseIdentifier model:(ServiceParametModel*)model
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.wbModel = model;
        [self drawRowInputSelectTableCell];
    }
    return self;
}

- (id)initWithSelectReuseIdentifier:(NSString *)reuseIdentifier model:(ServiceParametModel*)model
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.wbModel = model;
        [self drawRowSelectLabeCell];
    }
    return self;
}

- (id)initWithDateReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        [self drawRowDateLabeCell];
    }
    return self;
}

- (id)initWithSelectMultiReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        [self drawRowSelectMultiLabeCell];
    }
    return self;
}

- (id)initWithSwitchReuseIdentifier:(NSString *)reuseIdentifier target:(id)target switchs:(SEL)switchAction
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self drawRowSwitchLabeCellTarget:target switch:switchAction];
    }
    return self;
}

//多输入框
- (id)initWithFieldMultiIdentifier:(NSString *)reuseIdentifier type:(NSString*)typeString
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        [self drawTextFieldMultiCellType:typeString];
    }
    return self;
}

//普通单选框
- (id)initWithSwitchIdentifier:(NSString *)reuseIdentifier model:(ServiceParametModel*)model
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.wbModel = model;
        [self drawRowSwitchTableCell];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    if (!self.isChangeWidth) {
        frame.origin.x += 10;
        frame.size.width = SuperWidth - 20;
    }
    [super setFrame:frame];
}

#pragma mark - ERP模块调用

- (id)initWithSelectReuseIdentifier:(NSString *)reuseIdentifier request:(WebServiceCommonRequest*)connect
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.erpModel = connect;
        [self drawRowSelectLabeCell];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setPickerTextFieldComponents:(NSArray*)array keyValue:(NSArray*)keyValue
{
    if(array && keyValue){
        if (pickerTextField) [pickerTextField setComponents:array keyValue:keyValue];
    }
}

- (void)setAccessoryType:(UITableViewCellAccessoryType)accessoryType
{
    [super setAccessoryType:accessoryType];
    CGFloat textFieldWidth = self.frame.size.width - 85;
    
    if(field) {
        CGRect frame = field.frame;
        if(accessoryType != UITableViewCellAccessoryNone)frame.size.width = textFieldWidth - 21;
        else frame.size.width = textFieldWidth - 6;
        field.frame = frame;
        self.view.frame = frame;
        
    } else if(pickerTextField) {
        CGRect frame = pickerTextField.frame;
        if(accessoryType != UITableViewCellAccessoryNone)frame.size.width = textFieldWidth - 21;
        else frame.size.width  = textFieldWidth - 6;
        pickerTextField.frame = frame;
        self.view.frame = frame;
        
    } else if(multiPicker) {
        CGRect frame = multiPicker.frame;
        if(accessoryType != UITableViewCellAccessoryNone)frame.size.width = textFieldWidth - 21;
        else frame.size.width  = textFieldWidth - 6;
        multiPicker.frame = frame;
        self.view.frame = frame;
        
    } else if(dateTextField) {
        CGRect frame = dateTextField.frame;
        if(accessoryType != UITableViewCellAccessoryNone)frame.size.width = textFieldWidth - 21;
        else frame.size.width = textFieldWidth - 6;
        dateTextField.frame = frame;
        self.view.frame = frame;
    }
}

- (void)setMultiComponents:(NSArray*)array
{
    if (multiPicker && array) {
        [multiPicker setMultiComponents:array];
    }
}

- (void)setDatePickerMode:(UIDatePickerMode)pickerModel
{
    if (dateTextField){
        [dateTextField setDatePickerMode:pickerModel];
        [dateTextField setDefaultDate:[NSDate date]];
    }
}

- (void)setDatePickerMode:(UIDatePickerMode)pickerModel defaultDate:(NSDate*)date
{
    if (dateTextField){
        [dateTextField setDatePickerMode:pickerModel];
        [dateTextField setDefaultDate:date];
    }
}

- (void)setDefaultDateField:(NSDate*)date
{
    if (!dateTextField) return;
    
    if(date)[dateTextField setDefaultDate:date];
    else [dateTextField setText:@""];
}

- (void)setIsChangeWidth:(BOOL)isChangeWidth
{
    _isChangeWidth = isChangeWidth;
    if (!isChangeWidth) return;
    
    if(field) {
        CGRect frame = field.frame;
        frame.size.width += 20;
        field.frame = frame;
        self.view.frame = frame;
        
    } else if(pickerTextField) {
        CGRect frame = pickerTextField.frame;
        frame.size.width += 20;
        pickerTextField.frame = frame;
        self.view.frame = frame;
        
    } else if(multiPicker) {
        CGRect frame = multiPicker.frame;
        frame.size.width += 20;
        multiPicker.frame = frame;
        self.view.frame = frame;
        
    } else if(dateTextField) {
        CGRect frame = dateTextField.frame;
        frame.size.width += 20;
        dateTextField.frame = frame;
        self.view.frame = frame;
    }
}

#pragma 数据设置

- (void)setTitleName:(NSString *)titleName
{
    CGFloat width = [titleName widthAutoCalculateFontSize:[UIFont systemFontOfSize:16.0] andHeight:self.frame.size.height];
    titleLabel.text = titleName;
    
    CGFloat moveWidth = 0;
    CGRect titleFrame = titleLabel.frame;
    if (width > titleFrame.size.width) {
        titleFrame.size.width = width;
        moveWidth = width - titleFrame.size.width;
    }
    titleLabel.frame = titleFrame;
    
    if(field) {
        CGRect frame = field.frame;
        frame.size.width -= moveWidth;
        field.frame = frame;
        
    } else if(pickerTextField) {
        CGRect frame = pickerTextField.frame;
        frame.size.width -= moveWidth;
        pickerTextField.frame = frame;
        
    } else if(multiPicker) {
        CGRect frame = multiPicker.frame;
        frame.size.width -= moveWidth;
        multiPicker.frame = frame;
        
    } else if(dateTextField) {
        CGRect frame = dateTextField.frame;
        frame.size.width -= moveWidth;
        dateTextField.frame = frame;
    }
}

- (void)setInputFiled:(NSString *)inputFiled
{
    _inputFiled = inputFiled;
    
    if(field) field.text = inputFiled;
    else if(pickerTextField) pickerTextField.text = inputFiled;
    else if(multiPicker) multiPicker.text = inputFiled;
    else if(dateTextField) dateTextField.text = inputFiled;
}

- (void)setPlaceholder:(NSString *)placeholder
{
    _placeholder = placeholder;
    
    if(field) field.placeholder = placeholder;
    else if(pickerTextField) pickerTextField.placeholder = placeholder;
    else if(multiPicker) multiPicker.placeholder = placeholder;
    else if(dateTextField) dateTextField.placeholder = placeholder;
}

- (void)setIsMark:(BOOL)isMark
{
    if (isMark) self.markLabel.hidden = NO;
    else self.markLabel.hidden = YES;
}

- (void)setIsEdit:(BOOL)isEdit
{
    if(field) {
        field.userInteractionEnabled = isEdit;
        //field.hidden = !isEdit;
    }
}

- (void)setIsDirectEdit:(BOOL)isDirectEdit
{
    self.view.hidden = isDirectEdit;
}

- (void)setFieldWidthOffset:(CGFloat)fieldWidthOffset
{
    if(pickerTextField){
        CGRect fieldRect = pickerTextField.frame;
        fieldRect.size.width = self.frame.size.width - fieldWidthOffset;
        pickerTextField.frame = fieldRect;
        //修改遮住框大小
        if(self.view) view.frame = fieldRect;
    }
}

- (void)setActivityWidthOffset:(CGFloat)activityWidthOffset
{
    if (self.activity) {
        [activity setCenter:CGPointMake(self.frame.size.width - 40 + activityWidthOffset, 22)];
    }
}

//设置多输入框的值
- (void)setMultiTextFieldValue:(NSArray*)array
{
    if(!self.textFieldMulti) return;
    if(!array) return;
    
    NSMutableArray *mutlArray = [NSMutableArray array];
    for (id viewItem in self.textFieldMulti) {
        if ([viewItem isKindOfClass:[UITextField class]])
        [mutlArray addObject:viewItem];
    }
    
    if(array.count < mutlArray.count) return;
    for(int i=0; i<mutlArray.count; i++){
        UITextField *textField = [mutlArray objectAtIndex:i];
        textField.text = [NSString stringWithFormat:@"%@",[array objectAtIndex:i]];
    }
}

//获取多输入框的值
- (NSString*)getMultiTextFieldValue
{
    if(!self.textFieldMulti) return @"";
    NSMutableString *valueString = [NSMutableString string];
    
    for (id views in self.textFieldMulti) {
        if([views isKindOfClass:[UITextField class]]){
            UITextField *textField = views;
            [valueString appendString:textField.text];
            
        } else if([views isKindOfClass:[UILabel class]]){
            UILabel *label = views;
            [valueString appendString:label.text];
        }
    }
    
    return valueString;
}

//获取多输入框是否输入值
- (BOOL)isMultiTextFieldInputValue
{
    if(!self.textFieldMulti)
    {
      return NO;
    }
    for (id views in self.textFieldMulti) {
        if([views isKindOfClass:[UITextField class]]){
            UITextField *textField = views;
            if(textField.text.length <= 0)
            return NO;
        }
    }
    return YES;
}

#pragma UITextField

- (void)addTextFieldTarget:(id)target action:(SEL)action
{
    
}

- (void)addDoneTarget:(id)target action:(SEL)action
{
//    if(field) [field addDoneOnKeyboardWithTarget:target action:action];
//    else if(pickerTextField) [pickerTextField addDoneOnKeyboardWithTarget:target action:action];
//    else if(dateTextField) [dateTextField addDoneOnKeyboardWithTarget:target action:action];
    
    if(pickerTextField) [pickerTextField addDoneTarget:target action:action];
    if(multiPicker) [multiPicker addDoneTarget:target action:action];
    if(dateTextField) [dateTextField addDoneTarget:target action:action];
}

- (void)setEnablePrevious:(BOOL)isPreviousEnabled next:(BOOL)isNextEnabled
{
    if(pickerTextField) [pickerTextField setEnablePrevious:isPreviousEnabled next:isNextEnabled];
    else if(multiPicker) [multiPicker setEnablePrevious:isPreviousEnabled next:isNextEnabled];
    else if(dateTextField) [dateTextField setEnablePrevious:isPreviousEnabled next:isNextEnabled];
}

//编辑选择框事件
- (void)addEditSelectFieldTarget:(id)target action:(SEL)action
{
    if(editSelectButton){
        [editSelectButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
}

//设置键盘类型及输入过滤规则
- (void)setKeyboardType:(UIKeyboardType)keyboardType filter:(NSString*)filter
{
    if(field) {
        self.filter = filter;
        field.keyboardType = keyboardType;
        if(filter && filter.length>0) field.delegate = self;
        
    } else if(self.textFieldMulti){ //多输入框控制
        self.filter = filter;
        for (id views in self.textFieldMulti) {
            if([views isKindOfClass:[UITextField class]]){
                UITextField *textField = views;
                textField.keyboardType = keyboardType;
                if(filter && filter.length>0) textField.delegate = self;
            }
        }
    }
}

//设置键盘类型及输入过滤规则
- (void)setKeyboardType:(UIKeyboardType)keyboardType filter:(NSString*)filter block:(textFieldFilter)block
{
    self.textFieldFilter = block;
    [self setKeyboardType:keyboardType filter:filter];
}

//设置输入文字长度
- (void)setInputFiledLimitLength:(NSInteger)length
{
    self.filedLimitLength = length;
    if(self.textFieldMulti){ //多输入框控制
        for (id views in self.textFieldMulti) {
            if([views isKindOfClass:[UITextField class]]){
                UITextField *textField = views;
                if (!textField.delegate)
                textField.delegate = self;
            }
        }
    }
}

#pragma UITextFieldDelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    // return NO to not change text
    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:self.filter] invertedSet];
    NSString*filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    BOOL basicTest = [string isEqualToString:filtered];
    if(!basicTest) return NO;
    
    //设置输入文字长度过滤
    if(self.filedLimitLength > 0) {
        if ([string isEqualToString:@"\n"]) return NO;
        NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        if ([toBeString length] > self.filedLimitLength) {
            textField.text = [toBeString substringToIndex:self.filedLimitLength];
            return NO;
        }
    }
    
    //过滤方法（外部回执）
    if(self.textFieldFilter)
    return self.textFieldFilter(textField, range, string);
    
    return YES;
}

#pragma 获取网络数据

- (void)reloadData
{
    [self getNetWorkOrganizationDataCell];
}

#pragma 绘制页面

//普通输入框
- (void)drawRowInputTableCell
{
    CGSize cellSize = self.frame.size;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 65, cellSize.height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:titleLabel];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(68, 0, 16, cellSize.height)];
    markLabel.text = @"*";
    markLabel.textAlignment = NSTextAlignmentCenter;
    markLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:markLabel];
    
    self.field = [[UITextField alloc] initWithFrame:
                          CGRectMake(80, 0, self.frame.size.width - 85, self.frame.size.height)];
    field.font = [UIFont systemFontOfSize:15.0];
    field.textColor = [UIColor darkGrayColor];
    field.textAlignment = NSTextAlignmentRight;
    field.placeholder = @"";
    //field.hidden = YES;
    [self.contentView addSubview:field];
    
    self.view = [[UIView alloc] initWithFrame:field.frame];
    view.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:view];
    
    self.activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [activity setCenter:CGPointMake(self.frame.size.width - 40, 22)];
    [activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [activity startAnimating];
    [self.contentView addSubview:activity];
    
    //添加分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, SuperWidth, 1)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    
    //发送对象数据获取（公文机构职位树）
    if (self.wbModel) {
        [self getNetWorkOrganizationDataCell];
    } else {
        [activity stopAnimating];
        activity.hidden = YES;
    }
}

//输入选择框
- (void)drawRowInputSelectTableCell
{
    CGSize cellSize = self.frame.size;
    cellSize.width = SuperWidth - 20;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 65, cellSize.height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:titleLabel];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(68, 0, 16, cellSize.height)];
    markLabel.text = @"*";
    markLabel.textAlignment = NSTextAlignmentCenter;
    markLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:markLabel];
    
    self.pickerTextField = [[GEPickerTextField alloc] initWithFrame:
                            CGRectMake(80, 0, self.frame.size.width - 115, self.frame.size.height)];
    pickerTextField.font = [UIFont systemFontOfSize:15.0];
    pickerTextField.textAlignment = NSTextAlignmentRight;
    pickerTextField.textColor = [UIColor darkGrayColor];
    [pickerTextField setInputViewNull];
    [self.contentView addSubview:pickerTextField];
    
    self.editSelectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    editSelectButton.frame = CGRectMake(cellSize.width - 40, 8, 36, self.frame.size.height-16);
    [editSelectButton setImage:[UIImage imageNamed:@"ic_arrow_bottom_1"] forState:UIControlStateNormal];
//    editSelectButton.layer.masksToBounds = YES;
//    editSelectButton.layer.cornerRadius = 4.f;
//    editSelectButton.layer.borderWidth = 0.5f;
//    editSelectButton.layer.borderColor = [UIColor colorWithWhite:0.85 alpha:1].CGColor;
    [self.contentView addSubview:editSelectButton];
    
    self.view = [[UIView alloc] initWithFrame:pickerTextField.frame];
    view.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:view];
    
    self.activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [activity setCenter:CGPointMake(self.frame.size.width - 40, 22)];
    [activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [activity startAnimating];
    [self.contentView addSubview:activity];
    
    //添加分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, SuperWidth, 1)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    
    if (self.wbModel) {
        [self getNetWorkOrganizationDataCell];
    } else {
        [activity stopAnimating];
        activity.hidden = YES;
    }
}

- (void)drawRowSwitchLabeCellTarget:(id)target switch:(SEL)switchAction
{
    CGSize cellSize = self.frame.size;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 65, cellSize.height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:titleLabel];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(68, 0, 16, cellSize.height)];
    markLabel.text = @"*";
    markLabel.textAlignment = NSTextAlignmentCenter;
    markLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:markLabel];
    
    UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(SuperWidth - 80, 5, 0, 0)];
    switchView.on = NO;
    [self.contentView addSubview:switchView];
    
    self.activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [activity setCenter:CGPointMake(self.frame.size.width - 40, 22)];
    [activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    activity.hidden = YES;
    [activity stopAnimating];
    [self.contentView addSubview:activity];
    
    //添加分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, SuperWidth, 1)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    
    if(target && switchAction)
        [switchView addTarget:target action:switchAction forControlEvents:UIControlEventValueChanged];
}

//选择对话定制框
- (void)drawRowSelectLabeCell
{
    CGSize cellSize = self.frame.size;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 65, cellSize.height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:titleLabel];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(68, 0, 16, cellSize.height)];
    markLabel.text = @"*";
    markLabel.textAlignment = NSTextAlignmentCenter;
    markLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:markLabel];
    
    self.pickerTextField = [[GEPickerTextField alloc] initWithFrame:
                                CGRectMake(80, 0, self.frame.size.width - 85, self.frame.size.height)];
    pickerTextField.font = [UIFont systemFontOfSize:15.0];
    pickerTextField.textAlignment = NSTextAlignmentRight;
    pickerTextField.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:pickerTextField];
    
    self.view = [[UIView alloc] initWithFrame:pickerTextField.frame];
    view.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:view];
    
    self.activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [activity setCenter:CGPointMake(self.frame.size.width - 40, 22)];
    [activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [activity startAnimating];
    [self.contentView addSubview:activity];
    
    //添加分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, SuperWidth, 1)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    
    //发送对象数据获取（公文机构职位树）
    if (self.wbModel) {
        [self getNetWorkOrganizationDataCell];
    } if (self.erpModel){
        [self getNetWorkOrganizationERPDataCell];
    } else {
        [activity stopAnimating];
        activity.hidden = YES;
    }
}

//选择对话定制框
- (void)drawRowSelectMultiLabeCell
{
    CGSize cellSize = self.frame.size;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 65, cellSize.height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:titleLabel];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(68, 0, 16, cellSize.height)];
    markLabel.text = @"*";
    markLabel.textAlignment = NSTextAlignmentCenter;
    markLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:markLabel];
    
    self.multiPicker = [[GEMultiPickerTextField alloc] initWithFrame:
                            CGRectMake(80, 0, self.frame.size.width - 85, self.frame.size.height)];
    multiPicker.font = [UIFont systemFontOfSize:15.0];
    multiPicker.textAlignment = NSTextAlignmentRight;
    multiPicker.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:multiPicker];
    
    self.view = [[UIView alloc] initWithFrame:multiPicker.frame];
    view.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:view];
    
    self.activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [activity setCenter:CGPointMake(self.frame.size.width - 40, 22)];
    [activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [activity startAnimating];
    [self.contentView addSubview:activity];
    
    //添加分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, SuperWidth, 1)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    
    //关闭动画
    [activity stopAnimating];
    activity.hidden = YES;
    
    //发送对象数据获取（公文机构职位树）
//    if (self.wbModel) {
//        [self getNetWorkOrganizationDataCell];
//    } if (self.erpModel){
//        [self getNetWorkOrganizationERPDataCell];
//    } else {
//        [activity stopAnimating];
//        activity.hidden = YES;
//    }
}

//时间对话框
- (void)drawRowDateLabeCell
{
    CGSize cellSize = self.frame.size;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 65, cellSize.height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:titleLabel];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(68, 0, 16, cellSize.height)];
    markLabel.text = @"*";
    markLabel.textAlignment = NSTextAlignmentCenter;
    markLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:markLabel];
    
    CGRect frame = CGRectMake(80, 0, self.frame.size.width - 85, self.frame.size.height);
    self.dateTextField = [[GEDateTextField alloc] initWithFrame:frame];
    dateTextField.font = [UIFont systemFontOfSize:15.0];
    dateTextField.textAlignment = NSTextAlignmentRight;
    dateTextField.textColor = [UIColor darkGrayColor];
    [dateTextField setDatePickerMode:UIDatePickerModeDateAndTime];
    [dateTextField setDefaultDate:[NSDate date]];
    [self.contentView addSubview:dateTextField];
    
    self.view = [[UIView alloc] initWithFrame:dateTextField.frame];
    view.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:view];
    
    //添加分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, SuperWidth, 1)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    
}

//多输入框定制
- (void)drawTextFieldMultiCellType:(NSString*)typeString
{
    self.accessoryType = UITableViewCellAccessoryNone;
    CGSize cellSize = self.frame.size;
    //CGFloat widths = self.frame.size.width - 85;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 65, cellSize.height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:titleLabel];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(68, 0, 16, cellSize.height)];
    markLabel.text = @"*";
    markLabel.textAlignment = NSTextAlignmentCenter;
    markLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:markLabel];
    
    typeString = typeString ? typeString : @"";
    NSArray *typeArray = [typeString componentsSeparatedByString:@"[srk]"];
    
    CGFloat x = 0;
    CGFloat y = 4;
    CGRect superViewFrame = CGRectMake(0, y, self.frame.size.width - 85, self.frame.size.height - 16);
    UIView *superView = [[UIView alloc] initWithFrame:superViewFrame];
    
    self.textFieldMulti = [NSMutableArray array];
    for (NSString *value in typeArray) {
        if ([value isEqualToString:@""]) {
            UITextField *textField = [[UITextField alloc] initWithFrame:
                                      CGRectMake(x, y, self.frame.size.height - y, superViewFrame.size.height)];
            textField.font = [UIFont systemFontOfSize:13.0];
            textField.textColor = [UIColor darkGrayColor];
            textField.textAlignment = NSTextAlignmentCenter;
            textField.borderStyle = UITextBorderStyleRoundedRect;
            
            [self.textFieldMulti addObject:textField];
            [superView addSubview:textField];
            x+= self.frame.size.height - y;
            
        } else {
            UIFont *font = [UIFont systemFontOfSize:15.0];
            CGFloat lableWidth = [value widthAutoCalculateFontSize:font andHeight:superViewFrame.size.height]+10;
            x+= 3;
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, lableWidth, superViewFrame.size.height)];
            label.userInteractionEnabled=YES;
            UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTouchUpInside:)];
            [label addGestureRecognizer:labelTapGestureRecognizer];
            label.font = font;
            label.text = value;
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor darkGrayColor];
            
            [self.textFieldMulti addObject:label];
            [superView addSubview:label];
            x+= lableWidth + 3;
        }
    }
    
    superViewFrame.origin.x = self.frame.size.width - x - 8;
    superViewFrame.size.width = x;
    superView.frame = superViewFrame;
    [self.contentView addSubview:superView];
    
    //添加分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, SuperWidth, 1)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
}
//坍落度label点击事件
-(void)labelTouchUpInside:(UITapGestureRecognizer *)recognizer{
    
    UILabel *label=(UILabel*)recognizer.view;
    if ([label.text isEqualToString:@"-"]) {
        label.text = @"±";
    }else
    {
        label.text = @"-";
    }
}

//普通单选框
- (void)drawRowSwitchTableCell
{
    CGSize cellSize = self.frame.size;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 65, cellSize.height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:titleLabel];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(68, 0, 16, cellSize.height)];
    markLabel.text = @"*";
    markLabel.textAlignment = NSTextAlignmentCenter;
    markLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:markLabel];
    
    UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectMake(SuperWidth - 28 - 51, 6, 0, 0)];
    switchview.userInteractionEnabled = NO;
    [self.contentView addSubview:switchview];
    
    //添加分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, SuperWidth, 1)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
}

#pragma 获取网络数据

//重新获取公共接口数据
- (void)againGetWebServiceCommonRequest:(WebServiceCommonRequest*)model
{
    if (!model) return;
    
    self.erpModel = model;
    [self setInputFiled:@""];
    self.objectData = nil;
    [self getNetWorkOrganizationERPDataCell];
}

//重新获取数据
- (void)againGetServiceParamet:(NSDictionary*)model
{
    if (self.erpModel){
        [self.erpModel removeAllParameter];
        [self setInputFiled:@""];
        self.objectData = nil;
        
        for (NSString *key in model)
        [self.erpModel addParameterKey:key value:model[key] defaults:@""];
        [self getNetWorkOrganizationERPDataCell];
        
    } else {
        [activity stopAnimating];
        activity.hidden = YES;
    }
}

- (void)getNetWorkOrganizationDataCell
{
    self.userInteractionEnabled = NO;
    activity.hidden = NO;
    [activity startAnimating];
    [self setTextFieldHidden:YES placeholder:nil];
    
    ServiceConnect *content = [[ServiceConnect alloc] initWithMethodName:self.wbModel.methodName dataArray:self.wbModel];
    [content startConnectNetworkCompleted:^(ServiceResultModel *result, NSDictionary *userInfo) {
        self.userInteractionEnabled = YES;
        [activity stopAnimating];
        activity.hidden = YES;
        
        //添加数据，刷新页面
        if(result.resultArray && result.resultArray.count>0){
            self.objectData = result.resultArray;
            [self setTextFieldHidden:NO placeholder:self.placeholder];
        } else {
            [self setTextFieldHidden:NO placeholder:@"暂无数据"];
        }
    } failed:^(NSError *error, NSDictionary *userInfo) {
        NSLog(@"==failed===%@",error);
        [activity stopAnimating];
        activity.hidden = YES;
        self.userInteractionEnabled = YES;
        [self setTextFieldHidden:NO placeholder:@"暂无数据"];
        
    } abnormal:^(NSError *error, NSDictionary *userInfo) {
        NSLog(@"==abnormal===%@",error);
        [activity stopAnimating];
        activity.hidden = YES;
        self.userInteractionEnabled = YES;
        [self setTextFieldHidden:NO placeholder:@"网络异常"];
    }];
}

- (void)getNetWorkOrganizationERPDataCell
{
    self.userInteractionEnabled = NO;
    activity.hidden = NO;
    [activity startAnimating];
    [self setTextFieldHidden:YES placeholder:nil];
    
    [self.erpModel startAsyncConnectCompleted:^(ServiceResultModel *result, NSDictionary *userInfo) {
        self.userInteractionEnabled = YES;
        [activity stopAnimating];
        activity.hidden = YES;
        
        //添加数据，刷新页面
        NSArray *firstArray = nil;
        if(result.resultArray && result.resultArray.count>0)
            firstArray = [result.resultArray firstObject];
        
        if(firstArray && firstArray.count>0){
            self.objectData = firstArray;
            [self setTextFieldHidden:NO placeholder:self.placeholder];
        } else {
            [self setTextFieldHidden:NO placeholder:@"暂无数据"];
        }
    } failed:^(NSError *error, NSDictionary *userInfo) {
        NSLog(@"==failed===%@",error);
        [activity stopAnimating];
        activity.hidden = YES;
        self.userInteractionEnabled = YES;
        [self setTextFieldHidden:NO placeholder:@"暂无数据"];
        
    } abnormal:^(NSError *error, NSDictionary *userInfo) {
        NSLog(@"==abnormal===%@",error);
        [activity stopAnimating];
        activity.hidden = YES;
        self.userInteractionEnabled = YES;
        [self setTextFieldHidden:NO placeholder:@"网络异常"];
    }];
}

- (void)setTextFieldHidden:(BOOL)isHidden placeholder:(NSString*)placeholder
{
    if(field) field.hidden = isHidden;
    if(pickerTextField) pickerTextField.hidden = isHidden;
    
    if(field && placeholder) field.placeholder = placeholder;
    if(pickerTextField && placeholder) pickerTextField.placeholder = placeholder;
    
    if(field && placeholder) field.placeholder = placeholder;
    if(multiPicker && placeholder) multiPicker.placeholder = placeholder;
}

@end
